<?php
/**
 * Created by PhpStorm.
 * User: 23783
 * Date: 2018/3/9
 * Time: 12:58
 */

namespace Controllers\Pdf;

class TravelExpensePdf{
    protected $pdf;

    public function __construct()
    {
        global $tcPdf;
        $this->pdf  = $tcPdf;
    }

    /**
     * 生成差旅费报销单
     * @param $result
     */
    function CreatePdfDocument($result){
        $this->pdf->AddPage();
        // 设置文档信息
        $this->pdf->SetCreator('Lane');
        $this->pdf->SetAuthor('Lane');
        $this->pdf->SetTitle('差旅报销单');
        //删除预定义的打印 页眉/页尾
        $this->pdf->setPrintHeader(false);
        $this->pdf->setPrintFooter(false);
        //设置字体 - 正文标题的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', 'B', 15);
        $this->pdf->Write(20, '差旅费报销单', '', 0, 'C', true, 0, false, false, 0);
        //设置字体 - 正文内容的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', '', 10);
        //设置页面边幅：
        $this->pdf->Cell(140, 12, '差旅费报销单', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '是否归属募投:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, '是/否', 1, 1, 'C');
        $this->pdf->Cell(140, 6, '', 0, 0, 'C');
        $this->pdf->Cell(25, 6, '费用类别:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['paras']['USE'], 1, 1, 'C');
        //第二行
        $this->pdf->Cell(35, 6, '所属部门:', 1, 0, 'R');
        $this->pdf->Cell(35, 6, $result['UF_DEPARTMENT'], 1, 0, 'C');
        $this->pdf->Cell(35, 6, '申请人姓名', 1, 0, 'R');
        $this->pdf->Cell(35, 6, $result['USER_NAME'], 1, 0, 'C');
        $this->pdf->Cell(25, 6, '联系电话:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['PERSONAL_MOBILE'], 1, 1, 'C');
        //第三行
        $this->pdf->Cell(35, 6, '项目/预算编号:', 1, 0, 'R');
        $this->pdf->Cell(35, 6, '', 1, 0, 'C');
        $this->pdf->Cell(35, 6, '预算名称:', 1, 0, 'R');
        $this->pdf->Cell(35, 6, '', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '是否在预算内:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, '是/否', 1, 1, 'C');
        //第四行
        $this->pdf->Cell(35, 6, '接收方式:', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '转账/现金:', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '转账账户:', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '', 1, 0, 'R');
        $this->pdf->Cell(17.5, 6, '', 1, 0, 'R');
        $this->pdf->Cell(25, 6, '账户抬头:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, '', 1, 1, 'C');
        //第五行
        $this->pdf->Cell(52.5, 6, '出差目的地', 1, 0, 'C');
        $this->pdf->Cell(35, 6, '车船票,飞机票', 1, 0, 'C');
        $this->pdf->Cell(35, 6, '住宿费', 1, 0, 'C');
        $this->pdf->Cell(17.5, 12, '市内交通费', 1, 0, 'C');
        $this->pdf->Cell(50, 6, '其他费用', 1, 1, 'C');
        //第六行
        $this->pdf->Cell(35, 6, '起程', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '到达', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '人/天', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '金额', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '人/天', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '金额', 1, 0, 'C');
        $this->pdf->Cell(17.5, 6, '', 0, 0, 'C');
        $this->pdf->Cell(25, 6, '摘要', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '金额', 1, 1, 'C');
        //循环模式
        for ($i=0;$i<3;$i++){
            $this->pdf->Cell(35, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(17.5, 6, '', 1, 0, 'C');
            $this->pdf->Cell(25, 6, '', 1, 0, 'C');
            $this->pdf->Cell(25, 6, '', 1, 1, 'C');
        }
        $this->pdf->Cell(35, 6, '合计费用(大写)：', 1, 0, 'C');
        $this->pdf->Cell(105, 6, $result['CAPITALMONEY'], 1, 0, 'L');
        $this->pdf->Cell(25, 6, '合计费用(小写):', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['paras']['NUMBER'], 1, 1, 'L');

        //审批记录
        $stks_count = count($result['task']);
        $this->pdf->Cell(35, 6*$stks_count, '审批记录：', 1, 0, 'C');
        for ($tasks=0;$tasks<$stks_count;$tasks++){
            if($tasks>0){
                $this->pdf->Cell(35, 6,'' , 0, 0, 'L');
            }
            $this->pdf->Cell(155, 6, $result['task'][$tasks], 0, 1, 'L');
        }

        $this->pdf->Line($this->pdf->GetX()+190, $this->pdf->GetY()-6*$stks_count, $this->pdf->GetX()+190, $this->pdf->GetY(), $style=array('width'=>0.2));
        $this->pdf->Line(45, $y = $this->pdf->GetY(), 200, $y = $this->pdf->GetY(), $style=array('width'=>0.2));
        //输出PDF。第二个参数默认是I，是浏览器预览。D是下载
        $this->pdf->Output('PHP_TO_PDF.pdf', 'I');
    }
}